package com.augurit.common.system.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.entity.OmUserOrg;
import com.augurit.common.system.web.org.form.OmUserOrgForm;

public class OmUserOrgConverter {

	public static void convertToEntity(OmUserOrgForm form, OmUserOrg entity){
		if(form != null && entity != null){
			
			if(form.getUoId() != null)
				entity.setUoId(form.getUoId());
			
			if(form.getOrgId() != null)
				entity.setOrgId(form.getOrgId());
			
			if(form.getUserId() != null)
				entity.setUserId(form.getUserId());
			
			if(form.getIsMain() != null && form.getIsMain().trim().length() > 0)
				entity.setIsMain(form.getIsMain());
		}
	}
	
	public static OmUserOrgForm convertToForm(OmUserOrg entity){
		if(entity != null){
			OmUserOrgForm form = new OmUserOrgForm();

			form.setUoId(entity.getUoId());
			form.setOrgId(entity.getOrgId());
			form.setUserId(entity.getUserId());
			form.setIsMain(entity.getIsMain());
			return form;
		}else
			return null;
	}
	
	public static List<OmUserOrgForm> convertToForm(List<Object[]> list){
		if(list != null && list.size() > 0){
			List<OmUserOrgForm> result = new ArrayList();
			
			for(Object[] objs : list){
				OmUserOrgForm form = convertToForm((OmUserOrg)objs[0]);
				form.setOrgName((String)objs[1]);
				result.add(form);
			}
			
			return result;
		}else
			return null;
	}
}
